package com.enation.app.shop.front.policyInsurance.webController;


import com.enation.app.shop.front.policyInsurance.entity.SysArea;
import com.enation.app.shop.front.policyInsurance.service.JAreaManageMapper;
import com.enation.framework.action.JsonResult;
import com.enation.framework.util.JsonResultUtil;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Scope("prototype")
@Controller
@RequestMapping("web/getArea")
public class InsuranceAreaController {

    @Autowired
    private JAreaManageMapper jAreaManageMapper;

@RequestMapping("/getCity")
    public JsonResult getCity(int province_id) {
    List<SysArea> areaList = jAreaManageMapper.getCity(province_id);
    JSONArray json = new JSONArray();
    for(SysArea sysArea : areaList){
        JSONObject jo = new JSONObject();
        jo.put("id", sysArea.getProvince_id());
        jo.put("time", sysArea.getArea_name());
        json.put(jo);
    }
    if (areaList.size() < 0) {
        return JsonResultUtil.getErrorJson("");
    }
    return JsonResultUtil.getSuccessJson("");
}

    @RequestMapping("/getRegion")
    public JsonResult getRegion(int province_id,int city_id){
        List<SysArea> areaList = jAreaManageMapper.getRegion(province_id,city_id);
        if (areaList.size() < 0) {
            return JsonResultUtil.getErrorJson("");
        }
        return JsonResultUtil.getSuccessJson("");
    }

        @RequestMapping("/getStreet")
        public JsonResult getStreet(int province_id,int city_id,int region_id) {
            List<SysArea> areaList = jAreaManageMapper.getStreet(province_id,city_id,region_id);
            if (areaList.size() < 0) {
                return JsonResultUtil.getErrorJson("");
            }
            return JsonResultUtil.getSuccessJson("");

        }
            @RequestMapping("/getVillage")
            public JsonResult getVillage(int province_id,int city_id,int region_id,int street_id,int village_id) {
                List<SysArea> areaList = jAreaManageMapper.getVillage(province_id,city_id,region_id,street_id,village_id);
                if (areaList.size() < 0) {
                    return JsonResultUtil.getErrorJson("");
                }
                return JsonResultUtil.getSuccessJson("");
            }
}
